package com.liu.demo.config;


import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 *功能描述 配置国际化
 * @author QS.L
 * @date 2020/5/16
 */
public class MyLocalResolver implements LocaleResolver{


    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String language = httpServletRequest.getParameter("language");
        System.out.println("===============>"+language);
        Locale locale = Locale.getDefault();
        if (!StringUtils.isEmpty(language)){
            //zh_CN
            String[] split = language.split("_");
            //zh   CN
            locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
    }
}
